(ns pe.p55
  (:use pe.digits))

(defn palind? [n]
  (= n (revnum n)))

(defn pal-iter [n]
    (let [s (+ n (revnum n))]
      [(palind? s) s]))

(defn find-pal [n limit]
  (loop [it (pal-iter (bigint n)) numiter 1]
    (cond
      (true? (first it)) [true (last it) numiter]
      (= limit numiter) [false 0 numiter]
      :else (recur (pal-iter (last it)) (inc numiter)))))

(defn lychrel? [n] (not (first (find-pal n 50))))

(println (filter lychrel? (range 1 10000)))
(println (lychrel? 10000))
(println (count (filter lychrel? (range 1 10000))))

